﻿
@{
    ViewData["Title"] = "Index";
}


<form class="layui-form" action="">
    <fieldset class="layui-elem-field comfield" style="margin: 0">
        <div style="float:left">
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">角色名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="RoleName" lay-verify="RoleName" autocomplete="off" placeholder="请输入名称" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-inline">
                            <input type="text" name="Describe" lay-verify="" autocomplete="off" placeholder="请输入名称" class="layui-input">
                        </div>
                    </div>
                </div>

            </div>

        </div>

        <div style="float: left">
            <button class="layui-btn layui-btn-sm layui-btn-normal layui-btn-radius" lay-submit=""
                    lay-filter="demo1">
                <span class="layui-icon">
                    &#xe615;
                </span>查询
            </button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-normal layui-btn-radius">
                <span class="layui-icon">
                    &#xe639;
                </span>重置
            </button>
        </div>
    </fieldset>
</form>


<div class="layui-btn-group mytool">
    @*<button class="layui-btn layui-btn-normal layui-btn-sm" id="btnadd"><i class="layui-icon">&#xe654;</i>新增</button>
    <button class="layui-btn layui-btn-sm" id="btnedit"><i class="layui-icon">&#xe642;</i>编辑</button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" id="btndel"><i class="layui-icon">&#xe640;</i>删除</button>
    <button class="layui-btn layui-btn-warm layui-btn-sm" id="btnPower"><i class="layui-icon">&#xe630;</i>分配权限</button>*@
</div>

<table id="demo" lay-filter="test"></table>
<script type="text/html" id="checkboxTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="IsActive" value="{{d.IsActive}}" title="激活"
           lay-filter="IsActiveDemo" {{ d.IsActive == 1?'checked':'' }}>
</script>

<script type="text/html" id="barDemo">
    @*<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"><i class="layui-icon">&#xe615;</i>查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>*@
</script>
<script type="text/javascript">
    /*
*name:RoleInfoBis
*author:wenqing
*角色管理js
*/
    ; layui.use(['form', 'layedit', 'laydate', 'table', 'layer', 'manageCom'],
        function () {

            var form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate
                , manage = layui.manageCom
                , table = layui.table;

            //日期
            laydate.render({
                elem: '#date'
                , type: 'datetime'
            });
            //根据权限生成按钮
            manage.GenerateBtnByPower();
            //监听提交
            form.on('submit(demo1)', function (data) {
                tableIns.reload({
                    where: data.field
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });

                return false;
            });

            $(".mytool").on('click','#btn_add',
                function () {
                    layer.open({
                        type: 2,
                        title: '新增角色',
                        shadeClose: true,
                        //shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['893px', '600px'],
                        content: '/Manage/RoleInfo/AddRole")'
                    });
                });
            $('.mytool').on('click','#btn_edit',
                function () {
                    var checkStatus = table.checkStatus('demo');
                    var checkdata = checkStatus.data;
                    if (checkdata.length != 1) {
                        layer.msg("请选一条数据编辑！");
                        return;
                    }
                    layer.open({
                        type: 2,
                        title: '编辑角色',
                        shadeClose: true,
                        //shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['893px', '600px'],
                        content: '/Manage/RoleInfo/EditRole/' + checkStatus.data[0].Id
                    });
                });
            $('.mytool').on('click','#btn_power',
                function () {
                    var checkStatus = table.checkStatus('demo');
                    var checkdata = checkStatus.data;
                    if (checkdata.length != 1) {
                        layer.msg("请选一条数据编辑！");
                        return;
                    }
                    layer.open({
                        type: 2,
                        title: '分配角色权限',
                        shadeClose: true,
                        //shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['400px', '600px'],
                        content: '/Manage/RoleInfo/AddRolePower/?id=' + checkStatus.data[0].Id
                    });
                });

            $('.mytool').on('click','#btn_del',
                function () {
                    var checkStatus = table.checkStatus('demo');
                    var checkdata = checkStatus.data;
                    if (checkdata.length == 0) {
                        layer.msg("请选择要删除的数据支持批量删除！");
                        return;
                    }
                    layer.confirm('真的要删??', function (index) {
                        var postdata = [];
                        checkdata.forEach(function (value) {
                            postdata.push(value.Id);
                        });

                        //console.info(postdata);
                        $.ajax({
                            type: "post",
                            url: '/Manage/RoleInfo/RoleDelete")',
                            data: { ids: postdata },
                            success: function (data) {
                                console.info(data);
                                if (data.code === 0) {
                                    layer.msg("删除成功！!");
                                    //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                    tableIns.reload();
                                } else {
                                    layer.msg(data.msg);
                                }
                            }
                        });
                        layer.close(index);
                        //向服务端发送删除指令

                    });
                });
            //展示已知数据
            tableIns = table.render({
                elem: '#demo',
                url: '/Manage/RoleInfo/GetRoleInfo/'
                , height: manage.getHeight()
                , cols: [[ //标题栏
                    { checkbox: true, LAY_CHECKED: false } //默认全选
                    , { field: 'Id', title: 'Id', width: 80, sort: true }
                    , { field: 'RoleName', title: '角色名称', width: 220 }
                    , { field: 'Describe', title: '描述', width: 150 }
                    , { field: 'IsActive', title: '是否激活', width: 100, templet: '#checkboxTpl' }
                    , { field: 'UpdateTime', title: '修改时间', width: 180 }
                    , { field: 'CreateTime', title: '创建时间', width: 180, sort: true }
                    , { fixed: 'right', title: '操作栏', width: 210, align: 'center', toolbar: '#barDemo' }
                ]]
                //, skin: 'row' //表格风格
                , even: false
                , page: true //是否显示分页
                , limits: [5, 7, 10, 100]
                , limit: 10 //每页默认显示的数量
                , loading: true
            });

            //监听工具条
            table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                console.info(data);
                if (layEvent === 'detail') { //查看
                    layer.open({
                        type: 2,
                        title: '新增角色信息',
                        shadeClose: true,
                        //shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['893px', '600px'],
                        content: '/Manage/RoleInfo/EditRole/?Id=' + data.Id + '&type=2'
                    });
                } else if (layEvent === 'del') { //删除
                    layer.confirm('真的删除' + data.Id + '这行么', function (index) {
                        var postdata = [];
                        postdata.push(data.Id);
                        //console.info(postdata);
                        $.ajax({
                            type: "post",
                            url: '/Manage/RoleInfo/RoleDelete")',
                            data: { ids: postdata },
                            success: function (data) {
                                console.info(data);
                                if (data.code === 0) {
                                    layer.msg("删除成功！!");
                                    //obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                    tableIns.reload();
                                } else {
                                    layer.msg(data.msg);
                                }
                            }
                        });
                        layer.close(index);
                        //向服务端发送删除指令

                    });
                } else if (layEvent === 'edit') { //编辑
                    layer.open({
                        type: 2,
                        title: '编辑角色信息',
                        shadeClose: true,
                        //shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['893px', '600px'],
                        content: '/Manage/RoleInfo/EditRole/' + data.Id
                    });
                }
            });

        });

</script>
@*<script src="~/js/manage/business/RoleInfoBis.js"></script>*@